package jp.dodododo.dao.util;

/**
 * 
 * @author Satoshi Kimura
 */
public abstract class ClassUtil {
	public static String getShortName(Class<?> clazz) {
		String name = clazz.getName();
		int i = name.lastIndexOf('.');
		if (i < 0) {
			return name;
		}
		return name.substring(i + 1, name.length());
	}

	@SuppressWarnings("unchecked")
	public static <T> Class<T> forName(String name) {
		try {
			return (Class<T>) Class.forName(name);
		} catch (ClassNotFoundException e) {
			throw new RuntimeException(name, e);
		}
	}

	public static <T> T newInstance(Class<T> clazz) {
		try {
			return clazz.newInstance();
		} catch (InstantiationException e) {
			throw new RuntimeException(clazz.toString(), e);
		} catch (IllegalAccessException e) {
			throw new RuntimeException(clazz.toString(), e);
		}
	}
}
